package com.ruoyi.patrol.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.patrol.vo.PtWorkReportVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtWorkReport;
import com.ruoyi.patrol.service.IPtWorkReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 记录工单信息Controller
 *
 * @author linan
 * @date 2024-02-03
 */
@RestController
@RequestMapping("/work/report")
public class PtWorkReportController extends BaseController
{
    @Autowired
    private IPtWorkReportService ptWorkReportService;

    /**
     * 查询记录工单信息列表
     */
    @PreAuthorize("@ss.hasPermi('work:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtWorkReport ptWorkReport)
    {
        startPage();
        List<PtWorkReportVO> list = ptWorkReportService.selectPtWorkReportList(ptWorkReport);
        return getDataTable(list);
    }

    /**
     * 导出记录工单信息列表
     */
    @PreAuthorize("@ss.hasPermi('work:report:export')")
    @Log(title = "记录工单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PtWorkReport ptWorkReport)
    {
        List<PtWorkReportVO> list = ptWorkReportService.selectPtWorkReportList(ptWorkReport);
        ExcelUtil<PtWorkReportVO> util = new ExcelUtil<>(PtWorkReportVO.class);
        util.exportExcel(response, list, "记录工单信息数据");
    }

    /**
     * 获取记录工单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ptWorkReportService.selectPtWorkReportById(id));
    }

    /**
     * 新增记录工单信息
     */
    @PreAuthorize("@ss.hasPermi('work:report:add')")
    @Log(title = "记录工单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtWorkReport ptWorkReport)
    {
//        ptWorkReport.setSource(getSource());
        return toAjax(ptWorkReportService.insertPtWorkReport(ptWorkReport));
    }

    /**
     * 修改记录工单信息
     */
    @PreAuthorize("@ss.hasPermi('work:report:edit')")
    @Log(title = "记录工单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtWorkReport ptWorkReport)
    {
        return toAjax(ptWorkReportService.updatePtWorkReport(ptWorkReport));
    }

    /**
     * 删除记录工单信息
     */
    @PreAuthorize("@ss.hasPermi('work:report:remove')")
    @Log(title = "记录工单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ptWorkReportService.deletePtWorkReportByIds(ids));
    }

    @Log(title = "修改报修工单状态", businessType = BusinessType.UPDATE)
    @PutMapping("updateStatus")
    public AjaxResult updateStatus(@RequestBody Map<String, Object> param)
    {
        return ptWorkReportService.updateStatus(param);
    }

    @GetMapping("position")
    public AjaxResult position(Long id, String lon, String lat, int buffer){
        return ptWorkReportService.position(id, lon, lat, buffer);
    }
}
